<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>管理文件夹</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">

                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th style="width: 45px">序号</th>
                            <th style="width: 480px">文件名称</th>
                            <th>权限信息</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list" style="min-height: 600px"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_enginid = getQueryVariable('enginid') || 0;


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_mu_guan, data:{enginid: param_enginid}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var list = res.data.list;
                zhan_list(res.data.list, res.data.authArr)

                render_from();
            }
        });



        form.on('submit(add)', function(data){
            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.name').attr('dataid') || 0;
                    var auth = $(this).find('.auth').find('input').val();
                    list.push({
                        id:id,
                        auth:auth,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();


            facade.ajax({url: ask_engin_mu_guan, data:{list:list}}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });




    });

    var kongStr = '         ';

    function zhan_list(list, authArr) {
        for (var key in list){
            var str = '';
            var nums = parseInt(key)+1;
            str += '<tr>';
            str += '<td style="width: 45px">'+nums+'</td>';

            var kongge = '';
            for (var iii=1; iii<list[key].level; iii++){
                kongge += kongStr;
            }

            str += '<td style="width: 500px"><input type="text" class="layui-input name" dataid="'+list[key].id+'" value="'+kongge+list[key].name+'" readonly></td>';
            str += '<td>';
            str += '<div class="auth auth'+list[key].id+'" key="'+list[key].id+'"></div>';
            str += '</td>';
            str += '</tr>';
            $("#list_list").append(str);
            xmselect_list_duo('auth'+list[key].id, authArr, list[key].auth,);

            if(list[key].children.length > 0){
                zhan_list(list[key].children, authArr);
            }
        }
    }


</script>
</body>
</html>
